package com.arcgis.Viewer;

import java.io.IOException;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import com.esri.arcgis.beans.TOC.TOCBean;
import com.esri.arcgis.carto.IActiveView;
import com.esri.arcgis.carto.IFeatureLayer;
import com.esri.arcgis.carto.IGeoFeatureLayer;
import com.esri.arcgis.carto.ILayer;
import com.esri.arcgis.geodatabase.ICursor;
import com.esri.arcgis.geodatabase.IField;
import com.esri.arcgis.geodatabase.IRow;
import com.esri.arcgis.geodatabase.ITable;
import com.esri.arcgis.geodatabase.esriFieldType;
import com.esri.arcgis.geometry.esriGeometryType;
import com.esri.arcgis.interop.AutomationException;

public class AttributeTableFrame extends JFrame {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JScrollPane scroll_pane=null;
	/*static JTable table=null;
	static DefaultTableModel model=null;
	static Vector row = new Vector();
	static Vector data = new Vector();
	static Vector name = new Vector();*/
	
	public AttributeTableFrame(){
		initialize();
	}
	
	public void initialize() {
		this.setSize(350, 220);
		this.setContentPane(getScrollPane());
		this.setTitle("属性表");
		this.setVisible(true);
	}

	
	public JScrollPane getScrollPane(){
		if(scroll_pane==null){
			scroll_pane=new JScrollPane();
			scroll_pane.setBounds(2, 2, 300, 200);
			scroll_pane.setVisible(true);
		}
		return scroll_pane;
	}
	
	
	/*private static JTable CreateDataTableByLayer(ILayer []layer, String tableName)
    {
        //创建一个属性表
        
        //model =new DefaultTableModel();
        //取得ITable接口
        //ITable iTable = (ITable) layer;
        IField iField = null;
        Object columnTitle[]=null;
        Object tableData[]=null;
        //根¨´据Y每?个?字Á?段?的Ì?属º?性?建¡§立¢¡éDataColumn对?象¨®
        try {
			for (int i = 0; i < iTable.getFields().getFieldCount(); i++)
			{
			    iField = iTable.getFields().getField(i);
				// 新?建¡§一°?个?DataColumn并¡é设¦¨¨置?其?属º?性?
				columnTitle[i] = iField.getName();
				tableData[i] = iField.getDefaultValue();
				name.addElement(columnTitle);
				data.add(tableData[i]);
				row.add(row);
				
				
			}
		} catch (AutomationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        model.setDataVector(data, name);
        table=new JTable(model);
        scroll_pane.add(table);
        
        
        
        //dataTable=new JTable(tableData,columnTitle);
        iField = null;
        
        return table;
    }

	*/
	
	/*public static JTable CreateDataTable(ILayer[] pLayer, String tableName) throws AutomationException, IOException
    {
        //创ä¡ä建¡§空?DataTable
        JTable dataTable = CreateDataTableByLayer(pLayer[], tableName);
        //取¨?得Ì?图ª?层?类¤¨¤型¨ª
        String shapeType = getShapeType(pLayer);
        //创ä¡ä建¡§DataTable的Ì?行D对?象¨®
        Object dataRow[][] = null;
        //从ä¨®ILayer查¨¦询¡¥到Ì?ITable
        ITable pTable = (ITable) pLayer;
        ICursor pCursor = pTable.ITable_search(null, false);
        //取¨?得Ì?ITable中D的Ì?行D信?息¡é
        IRow pRow = pCursor.nextRow();
        int n = 0;
        while (pRow != null)
        {
            
            for (int i = 0; i < pRow.getFields().getFieldCount(); i++)
            {
            	for(int j=0;j<2000;j++){
            		//如¨?果?字Á?段?类¤¨¤型¨ª为aesriFieldTypeGeometry，ê?则¨°根¨´据Y图ª?层?类¤¨¤型¨ª设¦¨¨置?字Á?段?值¦Ì
                    if (pRow.getFields().getField(i).getType() == esriFieldType.esriFieldTypeGeometry)
                    {
                        dataRow[i][j] = shapeType;
                    }
                    //当Ì¡À图ª?层?类¤¨¤型¨ª为aAnotation时º¡À，ê?要°a素?类¤¨¤中D会¨¢有®DesriFieldTypeBlob类¤¨¤型¨ª的Ì?数ºy据Y，ê?
                    //其?存ä?储ä¡é的Ì?是º?标À¨º注Á¡é内¨²容¨Y，ê?如¨?此ä?情¨¦况?需¨¨将?对?应®|的Ì?字Á?段?值¦Ì设¦¨¨置?为aElement
                    else if (pRow.getFields().getField(i).getType() == esriFieldType.esriFieldTypeBlob)
                    {
                        dataRow[i][j] = "Element";
                    }
                    else
                    {
                        dataRow[i][j] = pRow.getValue(i);
                    }
			    }
                
            }
            model.removeRow(n);
            model.addRow(dataRow);
            table =new JTable(model);
            dataRow = null;
            n++;
            //为a保À¡ê证¡è效¡ì率¨º，ê?一°?次ä?只?装Á¡ã载?最Á?多¨¤条¬?记?录?
            if (n == 2000)
            {
                pRow = null;
            }
            else
            {
                pRow = pCursor.nextRow();
            }
        }
        return table;
    }
	
	
	public static  String getShapeType(ILayer pLayer)
    {
        IFeatureLayer pFeatLyr = (IFeatureLayer)pLayer;
        try {
			switch (pFeatLyr.getFeatureClass().getShapeType())
			{
			    case esriGeometryType.esriGeometryPoint:
			        return "Point";
			    case esriGeometryType.esriGeometryPolyline:
			        return "Polyline";
			    case esriGeometryType.esriGeometryPolygon:
			        return "Polygon";
			    default:
			        return "";
			}
		} catch (AutomationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
    }
*/
}
